//Simba JavaScript Document
$(document).ready(function() { 
//表格行鼠标移上改变样式
$('#dgbg').find('tr').hover(
	function(){ $(this).addClass('at'); },
	function(){ $(this).removeClass('at'); }
);
$('#dgbg1').find('tr').hover(
	function(){ $(this).addClass('at'); },
	function(){ $(this).removeClass('at'); }
);
$('.xlts').find('li').hover(
	function(){ $(this).addClass('at'); },
	function(){ $(this).removeClass('at'); }
);
$('.xlts').find('li').click(function(){
		$(this).parent().prev().val($(this).text());
		$(this).parent().hide();
	}
);

//操作按钮鼠标移上改变样式
$('#sr_cz').find('dt').hover(
	function(){ $(this).addClass('on'); },
	function(){ $(this).removeClass('on'); }
);

//标签切换改变样式
$('#sr_bq').find('li').click(function(){
	$('#sr_bq').find('li').each(function(){
		$(this).removeClass('on');
	});
	$(this).addClass('on');
});

//全选与取消全选
$('#checkall').click(function(){
	var chk = $(this).attr("checked");
	$('input[type=checkbox]').each(function(){
		$(this).attr("checked",chk);
	});
});
});

//弹出提示层背景变灰
function sTips(bg, tp){//弹出层
	$(bg).show();$(tp).show();
	var bch = document.body.clientHeight;
	var dch = document.documentElement.clientHeight;
	var bsh = document.body.scrollHeight;
	var dsh = document.documentElement.scrollHeight;
	var bh = Math.max(bch,dch,bsh,dsh);
	$(bg).height(bh);//灰层铺满页面
	var bst = document.body.scrollTop;
	var dst = document.documentElement.scrollTop;
	var st = Math.max(bst,dst);
	var bcw = document.body.clientWidth;
	var dcw = document.documentElement.clientWidth;
	var cw = Math.max(bcw,dcw);
	var bch = document.body.clientHeight;
	var dch = document.documentElement.clientHeight;
	var ch = "";
	if(Math.min(bch,dch)==0){ch = Math.max(bch,dch);}
	else{ch = Math.min(bch,dch);}
	var dh = tp.clientHeight;
	var dw = tp.clientWidth;
	$(tp).css("top",50);//定位提示层top
	$(tp).css("left",(cw - dw)/2);//定位提示层left
}
function hTips(bg, tp){//关闭层
	$(bg).hide();$(tp).hide();
}

function showT(a, b, c ,d ,e){
	var h = '<div id="b1" class="tips_bg"></div><div id="t1" class="tips_ts">';
	h += '<div class="tips_ts1"><b>提示信息</b><p onclick="' + e + '"><img src="images/tips_close.gif" width="15" height="15" /></p></div>';
	h += '<div class="tips_ts2"><dl><dt>';
	h += '<img src="images/icon_error.gif" width="50" height="50" /></dt><dd>';
	switch(a){
		case 1:
			h += '<img src="images/icon_right.gif" width="50" height="50" /></dt><dd>';
		case 2:
			h += '<img src="images/icon_error.gif" width="50" height="50" /></dt><dd>';
		case 3:
			h += '<img src="images/icon_question.gif" width="50" height="50" /></dt><dd>';
		case 4:
			h += '<img src="images/icon_warning.gif" width="50" height="50" /></dt><dd>';
	}
	h += '	<div><b>' + b + '</b></div>';
	h += '	<div class="ca">' + c + '</div>';
	h += '	<div><br /></div><div><input type="button" value="确定" class="btn1" onclick="' + d + '" /><input type="button" value="取消" class="btn1" onclick="' + e + '" /></div>';
	h += '</dd></dl></div><div class="tips_ts3"><img src="images/tips_b.gif" width="420" height="10" /></div></div>';
	document.getElementById("tipsdiv").innerHTML = h;

	$('#t1').show();$('#b1').show();
	var bch = document.body.clientHeight;
	var dch = document.documentElement.clientHeight;
	var bsh = document.body.scrollHeight;
	var dsh = document.documentElement.scrollHeight;
	var bh = Math.max(bch,dch,bsh,dsh);
	$('#b1').height(bh);//灰层铺满页面
	var bst = document.body.scrollTop;
	var dst = document.documentElement.scrollTop;
	var st = Math.max(bst,dst);
	var bcw = document.body.clientWidth;
	var dcw = document.documentElement.clientWidth;
	var cw = Math.max(bcw,dcw);
	var bch = document.body.clientHeight;
	var dch = document.documentElement.clientHeight;
	var ch = "";
	if(Math.min(bch,dch)==0){ch = Math.max(bch,dch);}
	else{ch = Math.min(bch,dch);}
	var dh = t1.clientHeight;
	var dw = t1.clientWidth;
	$('#t1').css("top",st - 50 + (ch - dh)/2);//定位提示层top
	$('#t1').css("left",(cw - dw)/2);//定位提示层left
}
function hideT(){//关闭层
	$('#t1').hide();$('#b1').hide();
}

function doAjax(url,param,funSuccess){
$.ajax({
		type: "POST",
		dataType: "json",
		url: url,
		cache: false,
		data: param,
		beforeSend: disAjaxLoading,
		success: funSuccess,
		complete: hideAjaxLoading,
		error: hideAjaxLoadingError,
		clearForm: true
		});
}
function doAjaxEx(url,param,funSuccess,funbefore,funcomplete,funError){
$.ajax({
		type: "POST",
		dataType: "json",
		url: url,
		cache: false,
		data: param,
		beforeSend: funbefore,
		success: funSuccess,
		complete: funcomplete,
		error: funError,
		clearForm: true
		});
}

function disAjaxLoading(){
$('#ajax_loading').show();
}
function hideAjaxLoading(){
$('#ajax_loading').hide();
}
function hideAjaxLoadingError(){
alert('系统异常...');
$('#ajax_loading').hide();
}

function funDefaultSuccess(ajaxResult){
	  if(ajaxResult.resultCode == 1){
	    alert("操作成功");
      }else{
        alert("操作失败："+ ajaxResult.message);
      }
}

function popForm(popDiv){
	pop(popDiv,80);
}

function pop(popDiv,top){
	popDiv.modal({position: [top,],
		persist:false,
	    overlayId: 'contact-overlay',
	    containerId: 'contact-container',
	    close: true});
}
function popFormClose(popDiv){
	$.modal.close();
}

function popFormForPersistEx(popDiv,top){
	popDiv.modal({position: [top,],
		persist:true,
	        overlayId: 'contact-overlay',
			containerId: 'contact-container'});
}
function popFormForPersist(popDiv){
	popFormForPersistEx(popDiv,80);
	}

//模拟post请求
function formPost(url,paraMap){
    $("body").append("<form id='__f' target='_self'></form>");
    $('#__f').attr('action',url);
    $('#__f').attr('method','post');
    $.each(paraMap,function(k,v){
      $('#__f').append("<input type='hidden' name='"+k+"' value='"+v+"' />");
    });
    //alert($('#__f').attr('action'));
    window.setTimeout((function(){$('#__f').submit();}),0)
}
//弹出客户信息页面
function gotoCustDetail(csutID){
	window.open('viewGetDetailCustomer.action?cID='+csutID, 'newwindow', 'height=400, width=800, top=200, left=300, toolbar=no, menubar=no, scrollbars=yes,resizable=yes,location=no, status=no');
}